package com.lz.date;

import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * LocalDateTest..
 *
 * @author Lizhong
 * @date 2019/3/27
 */
public class LocalDateTest {
    @Test
    public void test(){
            String s ="2019-03-03";
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate date = LocalDate.parse(s, fmt);
        System.out.println(date);
    }
    @Test
    public void String转LocalDate和LocalDateTime(){
        String str = "2017-11-21 14:41:06:612";
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS");
        LocalDate date = LocalDate.parse(str, fmt);
        LocalDateTime time = LocalDateTime.parse(str, fmt);
        System.out.println("date:"+date);
        System.out.println("time:"+time);
    }
}
